<?php

use Illuminate\Database\Seeder;
use App\User;

class UsersTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // 获取 faker 实例
        $faker = app(Faker\Generator::class);

        // 生成数据
        $users = factory(User::class)
                    ->times(10)
                    ->make();
        //让隐藏字段可见，并将数据集合转换为数组
        $user_array = $users->makeVisible(['password','remember_token'])->toArray();

        // 写入数据
        User::insert($user_array);

        // 特别设置第一个测试账号
        $user = User::find(1);

        $user->name = 'Eden';
        $user->email = 'test@163.com';
        $user->save();

        // 初始化用户角色，将 1 号用户指派为『管理员』
        $user->assignRole('Founder');
    }
}
